/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * HomePanl.java
 *
 * Created on 2010-mar-03, 13:07:02
 */

package dat215projekt.gui.components;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JToggleButton;
import se.chalmers.cse.dat215.project.IMatDataHandler;

/**
 *
 * @author Berget
 */
public class HomePanel extends javax.swing.JPanel {

    private static HomePanel instance;
    private JToggleButton home1, home2;
    
    /** Creates new form HomePanl */
    public HomePanel() {
        initComponents();
        instance = this;

        if(!IMatDataHandler.getInstance().isUserComplete()){
            header.setText("Välkommen till iMat!");
        }
        else{
            header.setText("Välkommen till iMat, "+IMatDataHandler.getInstance().getCustomer().getFirstName()+"!");
        }


        favoritesShortButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                home1.doClick();
            }
        });

        minaUppgifterButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                home2.doClick();
            }
        });
    }

    public void setButtonsRefs(JToggleButton b, JToggleButton b2){
        this.home1 = b;
        this.home2 = b2;
    }

    public static synchronized HomePanel getInstance(){
        return instance;
    }

    @Override
    public void paint(Graphics g){
        Rectangle r = g.getClipBounds();
        double height = r.getHeight();
        double width = r.getWidth();
        Dimension d = this.getParent().getSize();
        double pictX = pictLabel.getAlignmentX();
        double pictY = pictLabel.getAlignmentY();
        this.setPreferredSize(new Dimension((int)(pictLabel.getWidth()-this.getWidth()+width),
                                                (int)(pictLabel.getHeight()-this.getHeight()+height)));

        super.paint(g);
    }




    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        header = new javax.swing.JLabel();
        textLabel = new javax.swing.JLabel();
        pictLabel = new javax.swing.JLabel();
        favoritesShortButton = new javax.swing.JButton();
        minaUppgifterButton = new javax.swing.JButton();
        snabblankar = new javax.swing.JLabel();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(dat215projekt.Dat215projektApp.class).getContext().getResourceMap(HomePanel.class);
        setBackground(resourceMap.getColor("Form.background")); // NOI18N
        setName("Form"); // NOI18N

        header.setFont(resourceMap.getFont("header.font")); // NOI18N
        header.setForeground(resourceMap.getColor("header.foreground")); // NOI18N
        header.setText(resourceMap.getString("header.text")); // NOI18N
        header.setName("header"); // NOI18N

        textLabel.setFont(resourceMap.getFont("textLabel.font")); // NOI18N
        textLabel.setForeground(resourceMap.getColor("textLabel.foreground")); // NOI18N
        textLabel.setText(resourceMap.getString("textLabel.text")); // NOI18N
        textLabel.setName("textLabel"); // NOI18N

        pictLabel.setIcon(resourceMap.getIcon("pictLabel.icon")); // NOI18N
        pictLabel.setText(resourceMap.getString("pictLabel.text")); // NOI18N
        pictLabel.setName("pictLabel"); // NOI18N

        favoritesShortButton.setFont(resourceMap.getFont("favoritesShortButton.font")); // NOI18N
        favoritesShortButton.setForeground(resourceMap.getColor("favoritesShortButton.foreground")); // NOI18N
        favoritesShortButton.setText(resourceMap.getString("favoritesShortButton.text")); // NOI18N
        favoritesShortButton.setToolTipText(resourceMap.getString("favoritesShortButton.toolTipText")); // NOI18N
        favoritesShortButton.setBorderPainted(false);
        favoritesShortButton.setContentAreaFilled(false);
        favoritesShortButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        favoritesShortButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
        favoritesShortButton.setName("favoritesShortButton"); // NOI18N

        minaUppgifterButton.setFont(resourceMap.getFont("minaUppgifterButton.font")); // NOI18N
        minaUppgifterButton.setForeground(resourceMap.getColor("minaUppgifterButton.foreground")); // NOI18N
        minaUppgifterButton.setText(resourceMap.getString("minaUppgifterButton.text")); // NOI18N
        minaUppgifterButton.setToolTipText(resourceMap.getString("minaUppgifterButton.toolTipText")); // NOI18N
        minaUppgifterButton.setBorderPainted(false);
        minaUppgifterButton.setContentAreaFilled(false);
        minaUppgifterButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        minaUppgifterButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
        minaUppgifterButton.setName("minaUppgifterButton"); // NOI18N

        snabblankar.setFont(resourceMap.getFont("snabblankar.font")); // NOI18N
        snabblankar.setForeground(resourceMap.getColor("snabblankar.foreground")); // NOI18N
        snabblankar.setText(resourceMap.getString("snabblankar.text")); // NOI18N
        snabblankar.setName("snabblankar"); // NOI18N

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(header)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(textLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 435, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(layout.createSequentialGroup()
                                .add(30, 30, 30)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(favoritesShortButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(minaUppgifterButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(snabblankar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 8, Short.MAX_VALUE)
                        .add(pictLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 500, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(header, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 123, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(45, 45, 45)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(layout.createSequentialGroup()
                        .add(textLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(18, 18, 18)
                        .add(snabblankar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(favoritesShortButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 30, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(minaUppgifterButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 27, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(319, 319, 319))
                    .add(layout.createSequentialGroup()
                        .add(pictLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton favoritesShortButton;
    private javax.swing.JLabel header;
    private javax.swing.JButton minaUppgifterButton;
    private javax.swing.JLabel pictLabel;
    private javax.swing.JLabel snabblankar;
    private javax.swing.JLabel textLabel;
    // End of variables declaration//GEN-END:variables

}
